
"""
pytest中共享fixture模块
"""
import pytest
import requests
from common.tools import generate_random_string


@pytest.fixture
def token():
    """
    登录获取token
    :return:
    """
    url="http://api.yesapi.net/api/App/User/Login"
    data = {
        "app_key":"C5373B91D01DED52665D8983147EB611",
        "username": "lisi",
        "password":"e10adc3949ba59abbe56e057f20f883e"
    }
    r=requests.post(url,json=data)
    r=r.json()
    return r.get('data').get('token')

@pytest.fixture
def uuid():
    """
    注册获取uuid
    :return:
    """
    name=generate_random_string(5)
    url="http://api.yesapi.net/api/App/User/Register"
    data = {
        "app_key":"C5373B91D01DED52665D8983147EB611",
        "username": name,
        "password":"e10adc3949ba59abbe56e057f20f883e"
    }
    r=requests.post(url,json=data)
    r=r.json()
    return r.get('data').get('uuid')


@pytest.fixture
def admin_token():
    """
    登录获取admin的token
    :return:
    """
    url="http://api.yesapi.net/api/App/User/Login"
    data = {
        "app_key":"C5373B91D01DED52665D8983147EB611",
        "username": "lucky",
        "password":"e10adc3949ba59abbe56e057f20f883e"
    }
    r=requests.post(url,json=data)
    r=r.json()
    return r.get('data').get('token')



@pytest.fixture
def username():
    """
    注册获取username
    :return:
    """
    name=generate_random_string(5)
    url="http://api.yesapi.net/api/App/User/Register"
    data = {
        "app_key":"C5373B91D01DED52665D8983147EB611",
        "username": name,
        "password":"e10adc3949ba59abbe56e057f20f883e"
    }
    requests.post(url,json=data)
    return name